#!/usr/bin/perl
my $debug = 0;

# You may need to configure these to your environment
my $xcconfig = join( "/", $ENV{PROJECT_DIR}, "../MasterVersionSettings.xcconfig" );
my $source_plist = $ENV{PRODUCT_SETTINGS_PATH};
my $processed_plist = join( "/", $ENV{TEMP_FILES_DIR}, "Preprocessed-Info.plist" );

print "Running info.plist builder...\n\n" if( $debug );

my %vars = ();

# Read the xcconfig file for key = value pairs
if( !open( XCCONFIG, $xcconfig ) ) { die "Unable to open $xcconfig: $!\n"; }
while( &lt;XCCONFIG&gt; )
{
	chomp();

	next if( $_ =~ /^\/\// );
	next if( $_ =~ /^\s*$/ );

	my( $k, $v ) = split( /\s*=\s*/, $_, 2 );
	
	$vars{$k} = $v;
}

close( XCCONFIG );

if( $debug )
{
	while( my($k,$v) = each %vars )
	{
		print "$k: $v\n";
	}
}

# Replacements
my $eol = $/;
undef $/;
if( !open( SOURCE_PLIST, $source_plist ) ) { die "Unable to open $source_plist: $!\n"; }
my $input_plist = &lt;SOURCE_PLIST&gt;;
close( SOURCE_PLIST );
$/ = $eol;

while( my($k,$v) = each %vars )
{
	my $pattern = "\\\${$k}";
	$input_plist =~ s/$pattern/$v/g;
}

if( !open( OUTPUT_PLIST, "&gt;$processed_plist" ) ) { die "Unable to write to $processed_plist: $!\n"; }
print OUTPUT_PLIST $input_plist;
close( OUTPUT_PLIST );

print "plist has been created\n" if( $debug );